CC			= gcc
CXX			= g++
CFLAGS		= -O2 -pipe
CXXFLAGS	= $(CFLAGS) -std=c++11 -pthread
LDFLAGS		= -Llua -lluajit -lpthread -luuid -ldl

TARGET	= omni
OUTDIR	= ../publish
OBJDIR	= ../build/$(TARGET)

PATHS	= . api core utils

SRCS	= $(foreach PATH, $(PATHS), $(wildcard $(PATH)/*.cc) $(wildcard $(PATH)/*.c))
OBJS	= $(patsubst %.c, $(OBJDIR)/%.o, $(patsubst %.cc, $(OBJDIR)/%.o, $(SRCS)))
DIRS	= $(sort $(patsubst %/, %, $(dir $(OBJS))))

all: prebuild build

prebuild:
	@echo -e '\033[35m=== Start build $(TARGET) ...\033[0m'
	@test -d '$(DIRS)' | mkdir -p $(DIRS)

build: $(OBJS)
	@echo -e '\033[36mGenerate $(OUTDIR)/$(TARGET) ... \033[0m'
	@$(CXX) -o $(OUTDIR)/$(TARGET) $(OBJS) $(LDFLAGS)

clean:
	@rm -f $(OBJS) $(OUTDIR)/$(TARGET)

$(OBJDIR)/%.o: %.cc
	@echo -e '\033[33m--> Compile $< ...\033[0m'
	@$(CXX) $(CXXFLAGS) -c $< -o $@

$(OBJDIR)/%.o: %.c
	@echo -e '\033[33m--> Compile $< ...\033[0m'
	@$(CC) $(CFLAGS) -c $< -o $@